#!/usr/bin/env bash
. ./scripts/devcontainer/_assert-in-container "$0" "$@"

set -euo pipefail

all_yaml_files() {
  find ./* -type f \
    \( -name "*.yml" \
    -o -name "*.yaml" \) -print \
    -o -path ".git" -prune \
    -o -path "rundir" -prune \
    -o -path "./rundir" -prune \
    -o -path "backend/paket-files" -prune \
    -o -path "./backend/paket-files" -prune \
    -o -path ".circleci/config.yml" -prune
}

if [[ "$#" -eq 1 ]]; then
  yamllint "$1"
else
  echo "linting yaml files ..."
  all_yaml_files | xargs yamllint
fi
